

const mongoose = require('mongoose');

var express = require('express')
// 注意这里的声明
var profession = express()


const {createResponse}= require("../../util/createResponse/index");
const {businessCodes}= require("../../code/businessCodes/index");
const { professionService } = require('../../service/impl/professionService/professionService');


profession.post('/post/profession/add', async (req,res) => {
  let result
  try {
    let news  = req.body.news
    result =  await professionService.getIns().create(news)
  } catch (error) {
    console.log(error);
    createResponse(res,500,businessCodes.b2)
    return
  }
    createResponse(res,200,businessCodes.b1,result)
  })
  
  profession.post('/post/profession/findByIdAndDelete', async (req,res) => {
    let result
    try {
      let  id  = req.body.conditions.id
      result =  await professionService.getIns().findByIdAndDelete(id)
    } catch (error) {
      console.log(error);
      createResponse(res,500,businessCodes.b2)
      return
    }
      createResponse(res,200,businessCodes.b1,result)
    })
  
  profession.post('/post/profession/findByIdAndUpdate', async (req,res) => {
    let result
    try {
      let  id  = req.body.conditions.id
      let updates = req.body.updates
      result =  await professionService.getIns().findByIdAndUpdate(id,updates)
    } catch (error) {
      console.log(error);
      createResponse(res,500,businessCodes.b2)
      return
    }
      createResponse(res,200,businessCodes.b1,result)
    })
  
  /* 查询所有职业数据 */
  profession.post('/post/profession/queryProfessions', async (req,res) => {
    let result
    let fills = {
      "direction_id":"direction_id",
      "kemuIDArray":"kemuIDArray"
    }
    try {
     
      result =  await professionService.getIns().find(null,null,fills)
    } catch (error) {
      console.log(error);
      createResponse(res,500,businessCodes.b2)
      return
    }
      createResponse(res,200,businessCodes.b1,result)
    })





// 根据职业id,查询该职业包含的科目
profession.post('/post/profession/queryProfessionIncludeKemu',async (req,res) => {
  let result
  try {
    let conditions = {
      "_id":req.body.conditions.professionid
    }

    let fills = {
      "key1":{
        "path":"kemuIDArray"
      }
    }

    result =  await professionService.getIns().findOne(conditions,null,fills)

  } catch (error) {
    console.log(error);
    createResponse(res,500,businessCodes.b2)
    return
  }
    createResponse(res,200,businessCodes.b1,result)
  })

// 根据方向id,查询对应的职业
profession.post('/post/profession/queryProfessionByDirectionid',async (req,res) => {
  let result
  try {
    let conditions = {
      "direction_id":req.body.conditions.direction_id
    }
    result =  await professionService.getIns().find(conditions)
    
  } catch (error) {
    console.log(error);
    createResponse(res,500,businessCodes.b2)
    return
  }
    createResponse(res,200,businessCodes.b1,result)
  })




  
  module.exports= profession